package alf.mapping.view.visuals;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class BitmapCache {
	private Map<String,Bitmap> mapa = new HashMap<String,Bitmap>();

	public void clear() {
		mapa.clear();
	}

	public Bitmap get(String nameorpath) {
		Bitmap b = mapa.get(nameorpath);
		if (b == null) {
			File f = new File(nameorpath);
			if (f.exists()) { //only load bitmap if file exists.
				b = BitmapFactory.decodeFile(nameorpath);
				mapa.put(nameorpath, b);
			}
		}
		return b;
	}

	public void put(String name , Bitmap b) {
		mapa.put(name, b);
	}
}
